﻿// -----------------------------------------------------------------------
// <copyright file="ITodoListItemsContract.cs" company="Spardo, LLC">
// Copyright (c) 2011 SPardo, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the 
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
// </copyright>
// -----------------------------------------------------------------------

namespace DotNet37Signals.Client.Basecamp.Contracts
{
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using DotNet37Signals.Client.Basecamp.Models;
    using System;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    [ServiceContract]
    public interface ITodoListItemsContract : IBasecampContract
    {
        [OperationContract]
        [WebGet(UriTemplate = "/todo_lists/{todoListId}/todo_items.xml")]
        TodoItems GetList(string todoListId);

        [OperationContract]
        [WebGet(UriTemplate = "/todo_items/{todoItemId}.xml")]
        TodoItem Get(string todoItemId);

        [OperationContract]
        [WebInvoke(Method = "PUT", UriTemplate = "/todo_items/{todoItemId}/complete.xml")]
        void Complete(string todoItemId);

        [OperationContract]
        [WebInvoke(Method = "PUT", UriTemplate = "/todo_items/{todoItemId}/uncomplete.xml")]
        void Uncomplete(string todoItemId);

        [OperationContract]
        [WebGet(UriTemplate = "/todo_lists/{todoListId}/todo_items/new.xml")]
        TodoItemNew New(string todoListId);

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/todo_lists/{todoListId}/todo_items.xml")]
        NewEntity Create(string todoListId, TodoItemNew item);

        [OperationContract]
        [WebInvoke(Method = "PUT", UriTemplate = "/todo_items/{todoItemId}.xml")]
        void Update(string todoItemId, TodoItemNew item);

        [OperationContract]
        [WebInvoke(Method = "DELETE", UriTemplate = "/todo_items/{todoItemId}.xml")]
        void Delete(string todoItemId);

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/todo_lists/{todoListId}/todo_items/reorder.xml")]
        void Reorder(string todoListId, TodoItems list);
    }

    public static class TodoListItemsContractExtensions
    {
        public static TodoItems GetList(this ITodoListItemsContract contract, Int64 todoListId)
        {
            return contract.GetList(todoListId.ToString());
        }

        public static TodoItem Get(this ITodoListItemsContract contract, Int64 todoItemId)
        {
            return contract.Get(todoItemId.ToString());
        }

        public static void Complete(this ITodoListItemsContract contract, Int64 todoItemId)
        {
            contract.Complete(todoItemId.ToString());
        }

        public static void Uncomplete(this ITodoListItemsContract contract, Int64 todoItemId)
        {
            contract.Uncomplete(todoItemId.ToString());
        }

        public static TodoItemNew New(this ITodoListItemsContract contract, Int64 todoListId)
        {
            return contract.New(todoListId.ToString());
        }

        public static NewEntity Create(this ITodoListItemsContract contract, Int64 todoListId, TodoItemNew item)
        {
            return contract.Create(todoListId.ToString(), item);
        }

        public static void Update(this ITodoListItemsContract contract, Int64 todoItemId, TodoItemNew item)
        {
            contract.Update(todoItemId.ToString(), item);
        }

        public static void Delete(this ITodoListItemsContract contract, Int64 todoItemId)
        {
            contract.Delete(todoItemId.ToString());
        }

        public static void Reorder(this ITodoListItemsContract contract, Int64 todoListId, TodoItems list)
        {
            contract.Reorder(todoListId.ToString(), list);
        }
    }
}
